package com.codeoss.framework.view.util;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class DependObject {
	private Map<String,List<String>> dependNameMap=new HashMap<String,List<String>>();
	private Map<String,List<String>> dependAttrMap=new HashMap<String,List<String>>();
	
	public void add(String name,String dependName,String attr) {
		List<String> nameList=dependNameMap.get(name);
		if(nameList==null) {
			nameList=new ArrayList<String>();
			dependNameMap.put(name, nameList);
			nameList.add(dependName);
		}else {
			if(!nameList.contains(dependName)) {
				nameList.add(dependName);
			}
		}
		
		List<String> attrList=dependAttrMap.get(dependName);
		if(attrList==null) {
			attrList=new ArrayList<String>();
			dependAttrMap.put(dependName, attrList);
			attrList.add(attr);
		}else {
			if(!attrList.contains(attr)) {
				attrList.add(attr);
			}
		}
	}
	
	public List<String> getDependList(String name){
		return dependNameMap.get(name);
	}
	
	public List<String> getAttrList(String name){
		return dependAttrMap.get(name);
	}
	
	public boolean hasDepend(String name) {
		List<String> list=dependNameMap.get(name);
		if(list!=null && list.size()>0) {
			return true;
		}
		return false;
	}
}
